package com.example.es_demo.esrepository;

import com.example.es_demo.pojo.Student;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

import java.util.List;

/**
 * 通过jpa的使用模式简化es操作
 * 继承ElasticsearchRepository
 * 使用和spring-data-jpa类似
 */
public interface StudentEsRepository extends ElasticsearchRepository<Student, Long> {

    List<Student> findBySchoolLike(String school);

    List<Student> findByNameLikeAndSchool(String name,String school);


    @Query("{\"bool\": {\"must\": [\n" +
            "    {\"match\": {\"school\": \"?0\"}},\n" +
            "    {\"range\": {\"age\": {\n" +
            "        \"gt\": ?1,\n" +
            "        \"lt\": ?2\n" +
            "    }}}\n" +
            "]}}")
    List<Student> findBySchoolLikeAndAgeBetween(String school,int from,int to);


}
